package com.xwdeshj.controller;

import com.alibaba.fastjson.JSONObject;
import com.xwdeshj.service.XwFarmFoodinfoService;
import com.xwdeshj.utils.IMoocExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by BKWJA on 2019/1/6.
 * 农家乐——农家美食信息 控制层
 */
@Slf4j
@RequestMapping("farmfood")
@CrossOrigin(allowCredentials = "true")
@Controller
public class XwFarmFoodinfoController extends IMoocExceptionHandler {

    @Autowired
    private XwFarmFoodinfoService xwFarmFoodinfoService;

    /**
     * 获取农家乐店铺 美食信息
     * @param pageindex 当前页码
     * @param pagesize 每页显示多少
     * @param starttime 开始时间
     * @param endtime 结束时间
     * @param sortfild 排序字段
     * @param sortway 排序方式
     * @param searchval 搜索值
     * @param searchkey 搜索字段
     * @param farm_encryptId 店铺加密id
     * @return
     */
    @RequestMapping("/getfarmfoodlist")
    @ResponseBody
    public JSONObject getfarmfoodlist(@RequestParam(value = "pageindex",defaultValue = "1")Integer pageindex,
                                      @RequestParam(value = "pagesize",defaultValue = "10") Integer pagesize,
                                      @RequestParam(value = "starttime",defaultValue = "") String starttime,
                                      @RequestParam(value = "endtime",defaultValue = "") String endtime,
                                      @RequestParam(value = "sortfild",defaultValue = "farm_food_createtime")
                                              String sortfild,
                                      @RequestParam(value = "sortway",defaultValue = "desc")String sortway,
                                      @RequestParam(value = "searchval",defaultValue = "") String searchval,
                                      @RequestParam(value = "searchkey",defaultValue = "") String searchkey,
                                      String farm_encryptId, HttpServletRequest request){
        return xwFarmFoodinfoService.getfarmfoodlist(pageindex,pagesize,starttime,endtime,sortfild,sortway,
                searchval,searchkey,farm_encryptId,request);
    }


    /**
     *  新建 修改农家乐美食信息
     * @param food_id 美食id
     * @param foodType  套餐类型
     * @param foodremarks 说明
     * @param foodprice  价格
     * @param foodnum  数量
     * @param farm_encryptId 农家乐加密id
     * @param business_encryptId 店铺加密id
     * @param request
     * @return
     */
    @RequestMapping("/updatefarmfood")
    @ResponseBody
    public JSONObject updatefarmfood(Integer food_id,String foodType,String foodremarks,String foodprice,String foodnum,
                                     String farm_encryptId,String business_encryptId,HttpServletRequest request){
        return xwFarmFoodinfoService.updatefarmfood(food_id,foodType,foodremarks,foodprice,foodnum,
                farm_encryptId,business_encryptId,request);
    }

    /**
     * 根据美食id，删除对应的信息
     * @param food_id 美食id
     * @param request
     * @return
     */
    @RequestMapping("/delfarmfood")
    @ResponseBody
    public JSONObject delfarmfood(String food_id,HttpServletRequest request){
        return xwFarmFoodinfoService.delfarmfood(food_id,request);
    }

}
